package com.netdisk.demo.service.impl;

import com.netdisk.demo.entity.Authorities;
import com.netdisk.demo.dao.AuthoritiesDao;
import com.netdisk.demo.service.AuthoritiesService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Authorities)表服务实现类
 *
 * @author makejava
 * @since 2020-05-10 21:30:14
 */
@Service("authoritiesService")
public class AuthoritiesServiceImpl implements AuthoritiesService {
    @Resource
    private AuthoritiesDao authoritiesDao;

    /**
     * 通过ID查询单条数据
     *
     * @param  username 主键
     * @return 实例对象
     */
    @Override
    public Authorities queryById(String username) {
        return this.authoritiesDao.queryById(username);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<Authorities> queryAllByLimit(int offset, int limit) {
        return this.authoritiesDao.queryAllByLimit(offset, limit);
    }
    /**
     * @author Wang
     * @return 对象列表
     **/
    @Override
    public List<Authorities> queryAllAuthority() {
        return this.authoritiesDao.queryAllAuthority();
    }

    /**
     * 新增数据
     *
     * @param authorities 实例对象
     * @return 实例对象
     */
    @Override
    public Authorities insert(Authorities authorities) {
        this.authoritiesDao.insert(authorities);
        return authorities;
    }

    /**
     * 修改数据
     *
     * @param authorities 实例对象
     * @return 实例对象
     */
    @Override
    public Authorities update(Authorities authorities) {
        this.authoritiesDao.update(authorities);
        return this.queryById(authorities.getUserName());
    }

    /**
     * 通过主键删除数据
     *
     * @param  username 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String username) {
        return this.authoritiesDao.deleteById(username) > 0;
    }
}